DotModus Devs and Bevs - Kivy



Warning: This may get long and technical, but we end with pretty vids and pics! Promise!

Introduction

Why am I here?

Good question. This picture helps with the answer.

What do we have here?

  • One Python codebase
  • Native applications running on:
    • Ubuntu 18.04- Mouse + Keyboard
    • MSI Flxed Touch Screen (Ubuntu 18.04)
    • Windows 10 Tablet
    • MacOS 10.11 + MacOS 10.10
    • Android 8.1
    • An iPad running iOS 9.3
  • One happy developer

Why a Happy developer?

This question is easy to answer.

  • I can write my whole application in one language - Python
  • I can deploy that application to (almost) any platform
  • It's a fast, native app using hardware acceleration
  • It's modern, highly responsive and supports multi-touch
  • It completely free, both financially and legally (MIT licensed)
  • Completely self-contained - depends upon nothing but a CPU, GPU + C compiler
  • It makes my dumb-ass able to write apps for almost anything

What is Kivy?

Why is Kivy important?

Kivy is important in various ways.

  • Kivy is the only option for running Python on mobile devices.
  • It's free of any vendor specific technology or dependency - Google, Apple or Microsoft.
  • It still allows you to use vendor specific technologies.
  • It's MIT licensed - 100% transparent from end-to-end.

How Does Kivy Work?

Kivy takes a conceptually simple approach to minimizing OS dependencies.

  • Separates concerns into "Core abstractions"
    • InputProviders - Mouse, touch, keyboard, Kinect, gyroscope etc.
    • Graphics Backends - OpenGL ES 2.0 compatible providers (Supports DirectX11 via Angle)
    • CoreProviders - Window (SDL2), Text, Image, Audio, Video providers
  • Supplies a Python/Cython framework (as a library) which exposes CoreProviders
  • Supplies tools that produce OS specific bootstraps, which:
    • produce a packaged Python/Cython interpreter.
    • links to OS specific core providers.
    • includes any pure Python requirements with that interpreter.
    • compiles native OS binaries for C/C++/binary dependencies e.g. matplotlib, pillow for use on the target architecture.

Kivy Architecture

Why Use Kivy?

  • It facilitates novel and exciting interactions
    • Multi-touch, surface input
    • Mouse + Keyboard
    • 3D input via LeapMotion, Kinect or any other input provides
  • Allows for rich animation and multimedia experiences
  • Minimizes platform/OS differences - no browser, widget toolkit quirks
  • Simplifies testing and debugging - one local process, no artificial backend/frontend split
  • Carry UI/Framework learning across all platforms - Android Fragments? iOS segmented controls? WPF? UWP? WTF???
  • Open Source = you can fix your own problems

Why not use Kivy?

Whilst Kivy is great for many things, but it's not the solution for all problems.

  • Does not adopt the "look-and-feel" of native apps.
  • No "out-of-the-box" OS integration i.e. It's possible, but not always simple to leverage OS specific features.
  • Typically lags behind OS "bleeding-edge" features.
  • Packaging for different OS's requires understanding, experimention and patience.
  • Open Source = you have to fix your own problems. There are Google Forums and Discord channels, but often, it's up to you!

Cross-Platform Options - HTML5

HTML 5 solutions present various options for cross-platform deployment. These include:

  • Electron
  • Cordova
  • React
  • VueJS

They provide a safe and tested method of using skills and technologies across devices. A full discussion of their pros and cons could take days, so we briefly mention some of their inherent benefits and limitations.

Pros

  • Re-use web skills and tech for mobile apps.
  • Minimal deployment size.
  • Extensive support and skills available.

Cons

  • Complex - many moving parts (Javascript, HTML5, CSS + Backend/PHP/Python/C# etc).
  • Difficult to debug (in browser, declarative layout, complex CSS layout model).
  • Scalability - Weakly typed, lack of namespacing, clumsy imports/scoping.
  • Browser compatibility.
  • Limited native OS integration (browser sandbox).
  • Not built for multi-touch or rich animation/interaction.

HTML is a document presentation format and was never designed for interaction. Interaction has been added as an afterthought, which becomes very clear if you try to develop web apps!

Comparison Against Cross-Platform Game Engines

Game engine options include:

  • Unity
  • Unreal
  • Godot
  • Cocos2d
  • MonoGame

Game engines provide much more visual freedom, but often at the expense of ease-of-use.

Pros

  • Visual beauty and splendour.
  • Interactive freedom.
  • Scaleability.
  • Minimal cross platform quirks.
  • Widely used, with commercial support options available.
  • Local debugging and development.

Cons

  • Steep learning curve - 3D abstractions, models, physics, framework concepts etc.
  • Heavyweight deployment.
  • Lack of familiar desktop/mobile interfaces.
  • Limited native OS integration.
  • Difficult to interact with non-game hardware.

When not to use Kivy

We should always choose the best tool for the job at hand. It's great to love our tech, but it's essential that we understand it's limitations.

Kivy is probably not suitable when:

  • You need tight integration with, or the latest iOS/Android features? Go Android/iOS tooling!
  • You want you app to look-and-feel like other apps? Go Android/iOS tooling!
  • Your app is thin on logic? Go webpage!
  • You need to avoid installation / deployment? Go webpage!
  • You already have the webpage? Go Cordova!

Advantages of Kivy

If your app contains heavy logic, wants to look sexy, or needs unique interaction, Kivy is a great fit. It has many concrete advantages, good use cases and benefits:

  • Well designed, consistent, fluid layout sematics (vs. CSS's "!important" tag? Are you serious?).
  • Modern, event-based architecture.
  • Access to complete range of Python libraries (Note: Some may require recipes).
  • Can access native OS functionality if required (See plyer/pyjnius/pyobjus later).
  • Build on desktop, easily deploy to mobile or multi-touch devices.
  • Use Python for simplicity, switch to Cython for speed (do only if needed!).
  • Full stack framework:
    • Full GUI toolkit and runtime framework.
    • webdebugger - runs an embedded Flask web server serving runtime statistics.
    • inpector - real-time, interactive explorer of the GUI.
    • multistroke - a gesture lookup and recognition helper.
  • Rich Ecosystem of tools and libraries.

The Kivy Ecosystem

The core Kivy framework is kept minimal, to avoid bloat and including non-essential code. Useful tools, packages and extensions are offered as sister projects.

Some of these are:

  • buildozer - Helps deploy kivy application, mainly Android APKs.
  • kivy-ios - Builds XCode projects for iOS deployment.
  • pyjnius - Call Java (Android) from Python.
  • pyobjus - Call Objective C (iOS/MacOS) from Python.
  • python-for-android - Support core Android functions e.g. Services, Storage, Runtime permissions.
  • plyer - A platform-independent API to use features commonly found on various platforms, notably mobile.
  • kivy-garden - A collection of public repos for kivy widgets and components.

Noteworthy Kivy Projects

Many exicting and inspiring Kivy projects are out there. A few of the more interesting include:

  • Kivy 3D Gui - Drop you Kivy UI onto 3D models, easily create 3D interacitons.
  • Kivy GMaps - Integrate Google Maps into Kivy applications.
  • KivyMD - A Google Material Design widget set build in Kivy.
  • QrScan - QrCode scanner, built for Kivy, runs on iOS/Android/Desktop.
  • Kivy Lite Emulator - Test mobile device resolutions on your desktop.
  • KivyStudio - Adevelopment environment targeted towards fast testing and interactive mobile development.
  • Kivy Complete VM - A VirtualBox appliance for building Android APK's with minimal setup.

Kivy Showcase Examples

These examples demonstate some of the amazing things Kivy can and is doing.

In Summary

In summary, Kivy is a win on so many levels.

  • One Python code base everywhere - Android/iOS/Win/Mac/Linux/Pi
  • Open Source MIT license, from Code to complier
  • Designed, modern, consistent, event-driven Framework
  • Rich multimedia, multi-touch + interacive ability
    • Surfaces, wearables, mobiles
    • Edge computing, novel devices
  • Easy interation with low level devices/hardware via Cython/Pyobjus/Pyjnius
  • Design, test and debug locally.

In Closing

By developing Kivy skills inhouse, I believe DotModus could:

  • deliver Android, iOS, Windows and Mac applicaiton with one skill set.
  • supply touch devices (Pi + Touch screen) as hardware contollers / appliances.
  • deliver large interactive displays.
  • fondle their python in public.
From a personal perpective, Kivy gives Python developers unrivalled abilites to deliver attractive, exciting GUI applications with complete freedom.
** Open Source for the WIN **

Thank you

To Kivy users, I'm known as Zen-CODE.

Find me on Github: https://github.com/Zen-CODE

This presentation is available as a Jupyter notebook at https://github.com/Zen-CODE/kivybits/tree/master/Talks/2019

Thank you for listening to my rants.

Your patience is appreciated.